package com.axing.springbootinit.service.impl;

import com.axing.model.entity.InterfaceInfo;
import com.axing.springbootinit.common.ErrorCode;
import com.axing.springbootinit.exception.BusinessException;
import com.axing.springbootinit.exception.ThrowUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.axing.springbootinit.service.InterfaceInfoService;
import com.axing.springbootinit.mapper.InterfaceInfoMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author 13921
* @description 针对表【interface_info(接口信息)】的数据库操作Service实现
* @createDate 2025-03-24 14:52:02
*/
@Service
public class InterfaceInfoServiceImpl extends ServiceImpl<InterfaceInfoMapper, InterfaceInfo>
    implements InterfaceInfoService{


    @Override
    public void validInterfaceInfo(InterfaceInfo interfaceInfo, boolean add) {

            if (interfaceInfo == null) {
                throw new BusinessException(ErrorCode.PARAMS_ERROR);
            }

        Long id = interfaceInfo.getId();
        String name = interfaceInfo.getName();
        String description = interfaceInfo.getDescription();
        String url = interfaceInfo.getUrl();
        String requestHeader = interfaceInfo.getRequestHeader();
        String responseHeader = interfaceInfo.getResponseHeader();
        Integer status = interfaceInfo.getStatus();
        String method = interfaceInfo.getMethod();
        Long userId = interfaceInfo.getUserId();
        Date createTime = interfaceInfo.getCreateTime();
        Date updateTime = interfaceInfo.getUpdateTime();
        Integer isDelete = interfaceInfo.getIsDelete();

            // 创建时，参数不能为空
            if (!add) {
                ThrowUtils.throwIf(StringUtils.isAnyBlank(name, url, requestHeader,responseHeader,description,method), ErrorCode.PARAMS_ERROR);
            }

            // 有参数则校验
            if (StringUtils.isNotBlank(name) && name.length() > 80) {
                throw new BusinessException(ErrorCode.PARAMS_ERROR, "标题过长");
            }
            if (StringUtils.isNotBlank(name) && name.length() > 50) {
                throw new BusinessException(ErrorCode.PARAMS_ERROR, "内容过长");
            }

    }
}




